package com.education.api.controller.admin.education;

import com.education.business.service.system.ExamTaskService;
import com.education.common.utils.Result;
import com.education.model.subproject.ExamTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class ServerTimeController {
    @Autowired
    private ExamTaskService examTaskService;

    @GetMapping("/getExamCountdown")
    public Result getExamCountdown(@RequestParam Integer taskId) throws Exception {
        ExamTask examTask = examTaskService.ExamTaskById(taskId);
        int i =0;
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d1 = sd.parse(sd.format(date));
        Date d2 = sd.parse(sd.format(examTask.getEndTime()));
        if (examTask.getEndTime().getTime() - date.getTime()>0){
            i = (int) ((d2.getTime() - d1.getTime()) / (1000 * 60));
        }else {
            i = 0;
        }
        return Result.success(i);
    }


}
